<template>
	<view>
		<u-select v-model="show" :list="list" @confirm="confirm" :default-value="[1]"></u-select>
		<u-button @click="show = true" >
			学年学期查询
			<view class="img">
				<image src="../../static/img/find.png"></image>
			</view>
			
		</u-button>
		<!-- 顶部说明栏 -->
		<view class="top">
			<view class="uni-flex ">
				<view class="flex-item uni-bg-red">课程数量:{{total}}</view>
				<view class="flex-item uni-bg-green">平均绩点:</view>
				<view class="flex-item uni-bg-blue">通过学分:{{result}}</view>
			</view>
		</view>
		<!-- 学年成绩展示 -->
		<view class="show_score ">
			<view class="flex-item-V uni-flex  score_show" v-for="(item,index) in score" :key="item.id">
				<view class="show uni-bg-red">
					{{item.kcmc}}
					<view class="">
						{{item.xdfsmc}} {{item.xf}}学分
					</view>
				</view>
				<view class="score">{{item.zcj}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				xnxqdm: '202001', //用户选择的学年数据
				show: false,
				list: [], //获取学年数据
				total: '', //课程总数
				sum: 0, //通过学分
				score: [], // 存储每学年成绩分数数据
			}
		},
		onLoad() {
			this.getScore(),
			this.getlist()
		},
		methods: {
			// 获取每学期值
			async getlist() {
				const res = await this.$myRequest({
					url: '/api/getlist',
				})
				this.list = res.data.list
			},
			// 获取每学年成绩分数数据
			async getScore() {
				const res = await this.$schoolRequest({
					url: '/xskccjxx!getDataList.action',
					method: 'POST',
					data: {
						xnxqdm: this.xnxqdm
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded',
						'X-Requested-With': 'XMLHttpRequest',
						'Cookie': uni.getStorageSync("sessionid"),
					},
					success: (res) => {
						this.total = res.data.total
						this.score = res.data.rows
					},
					fail: (err) => {
						console.log(err)
					}
				})
			},
			// 点击按钮确定返回当前选择值
			confirm(e) {
				this.xnxqdm = e[0].value
				this.getScore()
			}
		},
		computed: {
			// 计算课程总学分
			result: function() {
				let sum = 0;
				for (let i = 0; i < this.score.length; i++) {
					//console.log(this.tasks[i].xf)
					sum+=parseFloat(this.score[i].xf)
					//console.log(this.sum)
				}
				return sum
			}
		}
	}
</script>

<style lang="scss">
	.img{
		width: 50rpx;
		height: 50rpx;
		image{
			height: 100%;
			width: 100%;
		}
		
	}
	.flex-item {
		width: 33.3%;
		height: 100%;
		text-align: center;
		//line-height: 100px;
	}
	/*成绩查询通用*/
	.top {
		/* width:690rpx; */
		padding: 0;
		height: 60rpx;
	}
	.uni-flex {
		display: flex;
		flex-direction: row;
	}
	
	/* 背景色 */
	.uni-bg-red {
		background: #F76260;
		color: #FFF;
	}
	
	.uni-bg-green {
		background: #09BB07;
		color: #FFF;
	}
	
	.uni-bg-blue {
		background: #007AFF;
		color: #FFF;
	}
	
	/*成绩展示*/
	.flex-item-V {
		width: 90%;
		height: 150rpx;
		margin: 10px auto;
		border: 1px solid $uni-bg-color-mask;
		border-radius: 10px;
	}
	.score_show {
		.score {
			//width: 20%;
			margin: 50rpx auto;
		}
	
		.show {
			width: 80%;
		}
	}
</style>
